package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ${郭冬胜}
 * @date 2025/7/15 9:10
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @RequestMapping("/full")
    public Object full(String newDate){
        List<Map> full = userService.full(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray objects = new JSONArray();

        for (Map map : full) {
            objects.add(map.get("name"));
        }
        data.put("categories",objects);

        JSONArray objects1 = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","总金额");
        objects1.add(jsonObject1);
        JSONArray objects2 = new JSONArray();
        for (Map map : full) {
            objects2.add(map.get("a"));
        }
        jsonObject1.put("data",objects2);



        data.put("series",objects1);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/fullA")
    public Object fullA(String newDate){
        List<Map> maps = userService.fullA(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("c"));
            objects.add(jsonObject1);
        }
        jsonObject.put("data",objects);
        return jsonObject;
    }
    @RequestMapping("/fullB")
    public Object fullB(String newDate){
        List<Map> maps = userService.fullB(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("d"));
            objects.add(jsonObject1);
        }
        jsonObject.put("data",objects);
        return jsonObject;
    }
    @RequestMapping("/fullC")
    public Object fullC(String newDate){
        List<Map> full = userService.fullC(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        JSONObject data = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","品牌");
        jsonObject1.put("id","subsys");
        objects.add(jsonObject1);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","性别");
        jsonObject2.put("id","module");
        objects.add(jsonObject2);
        data.put("columns",objects);

        JSONArray objects1 = new JSONArray();
        for (Map map : full) {
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("name",map.get("name"));
            jsonObject3.put("value",map.get("b"));
            objects1.add(jsonObject3);
        }
        data.put("rows",objects1);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
